import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.Date;
import java.util.concurrent.TimeoutException;

/**
 * @Author： yu.Tan
 * @Date: 2020/8/19 13:48
 * @Description:
 */
public class ProducerTest001 {
    private static final String SIMPLE_QUEUE_NAME = "MQ_SIMPLE_QUEUE";

    private static final String SIMPLE_QUEUE_MESSAGE = "Hello World!" + new Date();

    public static void main(String[] args) {
        Connection connection = MQConnecitonUtils.getConnection();

        Channel channel = null;

        try {
            channel = connection.createChannel();

            channel.queueDeclare(SIMPLE_QUEUE_NAME, false, false, false, null);
            channel.basicPublish("", SIMPLE_QUEUE_NAME, null, SIMPLE_QUEUE_MESSAGE.getBytes("UTF-8"));

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (channel != null) {
                    channel.close();
                }
                if (connection != null) {
                    connection.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            } catch (TimeoutException e) {
                e.printStackTrace();
            } finally {

            }
        }
    }


}
